function consultant_lister(from,direction,container_id,timeout)
{
	var container = "#"+container_id;
	$(container).parent().prepend('<div class="loader" style="margin-top:-20px;margin-left:'+parseInt($(container).parent().width()-20)+'px;"></div>');
	from = from;
	action = 'Slider';
	module = 'consultant';
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            //get errors from backend
            if(req.responseText)
            {
                $.facebox(req.responseText);
            }
			//get data from backend		
            if (req.responseJS.output)
            {
				$(".loader").remove();
            	nav = req.responseJS.navigation;
            	switch(direction)
            	{
            		case 'prev':
            			$(container+' .Slider-content-scroller').width(parseInt(width*2)+'px');
            			$(container+' .Slider-content-scroller').css("left",'-'+width+'px');
            			$(container+' .Slider-content-scroller').prepend('<div class="Slider-content-changeble Slider-content-changeble-vision">'+req.responseJS.output+'</div>');
		            	$(container+' .Slider-content-scroller')
							.animate(
								{
									'left':'+='+width+'px'
								},
								timeout,
								'linear',
								function()
								{
									$(this).children('.Slider-content-changeble').each(function()
									{
										if(!$(this).hasClass('Slider-content-changeble-vision')){$(this).remove();}
									});
									$(container+' .Slider-content-changeble-vision').removeClass('Slider-content-changeble-vision');
									$(container+' .Slider-content-scroller').css("width",width+'px');
									$(container+' .Slider-content-scroller').css("left",'0px');
								}
							);
            		break;
            		case 'next':
            			$(container+' .Slider-content-scroller').width(parseInt(width*2)+'px');
            			$(container+' .Slider-content-scroller').append('<div class="Slider-content-changeble Slider-content-changeble-vision">'+req.responseJS.output+'</div>');
		            	$(container+' .Slider-content-scroller')
							.animate(
								{
									'left':'-='+width+'px'
								},
								timeout,
								'linear',
								function()
								{
									$(this).children('.Slider-content-changeble').each(function()
									{
										if(!$(this).hasClass('Slider-content-changeble-vision')){$(this).remove();}
									});
									$(container+' .Slider-content-changeble-vision').removeClass('Slider-content-changeble-vision');
									$(container+' .Slider-content-scroller').css("width",width+'px');
									$(container+' .Slider-content-scroller').css("left",'0px');
								}
							);
            		break;
            	}
            	if(nav.prev_link == false)
            	{
            		if($(".Slider-prev-active"))
            		{
            			$(".Slider-prev-active").removeClass("Slider-prev-active").addClass("Slider-prev-unactive");
            		}
            	}
            	else if($(".Slider-prev-unactive"))
				{
					$(".Slider-prev-unactive").removeClass("Slider-prev-unactive").addClass("Slider-prev-active");
				}
            	if(nav.next_link == false)
            	{
            		if($(".Slider-next-active"))
            		{
            			$(".Slider-next-active").removeClass("Slider-next-active").addClass("Slider-next-unactive");
            		}
            	}
            	else if($(".Slider-next-unactive"))
				{
					$(".Slider-next-unactive").removeClass("Slider-next-unactive").addClass("Slider-next-active");
				}
            	$(".Slider-navigation-from").val(nav.from);
            }
		}
    }
	var width = $(container+' .Slider-content-scroller').width();
	var height = $(container+' .Slider-content-scroller').height();
    // Prepare request object (automatically choose GET or POST).
    req.open(null, PathToAjaxBackend, true);
	req.send({from:from,module:module,action:action});
}
$(document).ready(function(){
	$(".Slider-prev-active").live('click',function(){
		from = parseInt($(".Slider-navigation-from").val());
		consultant_lister(parseInt(from-1),'prev',$(this).siblings(".Slider-content").attr("id"),'normal');
	});
	$(".Slider-next-active").live('click',function(){
		from = parseInt($(".Slider-navigation-from").val());
		consultant_lister(parseInt(from+1),'next',$(this).siblings(".Slider-content").attr("id"),'normal');
	});
});
